package org.oslims.domain;

import java.io.Serializable;

import net.sf.gilead.pojo.gwt.LightEntity;

import com.google.gwt.validation.client.interfaces.IValidatable;

public abstract class AbstractBaseEntity extends LightEntity implements BaseEntity, Serializable, IValidatable, Comparable<AbstractBaseEntity> {

	/**
	 * 
	 */
	private static final long serialVersionUID = -2296316034359560256L;

	@Override
	public boolean isTransient() {
		return getId() == null;
	}

	public boolean equals(Object obj) {
		if (!(obj instanceof BaseEntity))
			return false;
		BaseEntity other = (BaseEntity) obj;
		if (this.getId() == null || other.getId() == null) {
			return false;
		}
		return this.getId() != null && this.getId().equals(other.getId());
	}

	public int hashCode() {
		return this.getId() != null ? this.getId().hashCode() : super.hashCode();
	}

	@Override
	public int compareTo(AbstractBaseEntity arg0) {
		// TODO Auto-generated method stub

		if (this.getId() == null || arg0.getId() == null) {
			return 1;
		}
		return this.getId().compareTo(arg0.getId());
	}
}
